mwan3: add new readfile function to speedup variable read from file
authorEtienne Champetier <[email protected]>
Fri, 11 Jul 2025 21:23:28 +0000 (17:23 -0400)
committerFlorian Eckert <[email protected]>
Fri, 1 Aug 2025 11:03:01 +0000 (13:03 +0200)
This is a preparation for adding an utility function readfile() to read
directly to a variable. Using '$(cat ...)' causes a fork/execve which is
extremely slow just to read '~2' chars.

(commit message from Florian Eckert)
Signed-off-by: Etienne Champetier <[email protected]>
net/mwan3/files/lib/mwan3/common.sh

index ecd45026e8db6c863889d4f3105726b0c4c3ff2f..953cd6665e09c4b4de04beb8e63e117e12dbc9f5 100644 (file)
@@ -86,6 +86,12 @@ mwan3_get_src_ip()
        export "$1=$_src_ip"
 }
 
+readfile() {
+       [ -f "$2" ] || return 1
+       # read returns 1 on EOF
+       read -d'\0' $1 <"$2" || :
+}
+
 mwan3_get_mwan3track_status()
 {
        local track_ips pid